import { Component } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { _HttpClient } from '@delon/theme';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzModalRef } from 'ng-zorro-antd/modal';

@Component({
  selector: 'app-sys-user-all-limit',
  templateUrl: './all-limit.component.html'
})
export class SysUserAllLimitComponent {
  i: any;
  allowIp?: string = '';
  banIp?: string = '';
  ipRemark?: string = '';
  validateForm: FormGroup;
  controlsConfig = {
    allowIp: ['', []],
    banIp: ['', []],
    ipRemark: ['', []]
  };
  companies = [];

  constructor(private modal: NzModalRef, private msgSrv: NzMessageService, public http: _HttpClient, private fb: FormBuilder) {
    this.validateForm = this.fb.group(this.controlsConfig);
  }

  ngOnInit(): void {
    //console.log(this.i);
    this.http.get(`api/user/all_limit`).subscribe(res => {
      this.allowIp = res.data.allow_ip;
      this.banIp = res.data.ban_ip;
      this.ipRemark = res.data.ip_remark;
      this.i = res.data;
    });
  }

  save(value: any): void {
    this.http.put(`api/user/all_limit`, value).subscribe(res => {
      if (res.err_code != 0) {
        this.msgSrv.error(res.msg);
        return;
      }
      this.msgSrv.success(res.msg);
      this.modal.close(true);
    });
  }

  close(): void {
    this.modal.destroy();
  }
}
